import cv2
import numpy as np
from matplotlib import pyplot as plt  # 需要安装matplotlib库

# author: 徐锐
# 直方图创建


def image_hist(image):
    color = ('blue', 'green', 'red')
    for i, color in enumerate(color):
        hist = cv2.calcHist([image], [i], None, [256], [0, 256])
        plt.plot(hist, color=color)
        plt.xlim([0, 256])
    plt.show()


# 测试
if __name__ == "__main__":
    img = cv2.imread("5.jpg")
    image_hist(img)
